#include<bits/stdc++.h>
using namespace std;
//#define LL long long
int T;
int n,m,L,VV;
int D[1000005];
int A[1000005];
int V[1000005];
int cesu[1000005];
int cnt;
vector <int> v1;
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    cin>>T;
    for(int i=1;i<=T;i++){
        cin>>n>>m>>L>>VV;
        for(int i=1;i<=n;i++){
            int a,b,c;
            cin>>a>>b>>c;
            D[i]=a;
            V[i]=b;
            A[i]=c;

        }
        for(int i=1;i<=m;i++){
            int a;
            cin>>a;
            cesu[i]=a;
        }
        for(int i=1;i<=n;i++){
            if(V[i]>VV) v1.push_back(D[i]);
        }
        cout<<v1.size()<<' ';
        sort(v1.begin(),v1.end());
        int sz=v1.size();
        int chao=v1[sz-1];
        for(int i=1;i<=m;i++){
            if(cesu[i]<chao) cnt++;
        }
        cout<<cnt<<endl;
    }
}
